package com.nomito.minimito.controller.front;

import com.nomito.minimito.common.utils.R;
import com.nomito.minimito.service.ImGroupService;
import com.nomito.minimito.service.ImGroupfriendService;
import com.nomito.minimito.service.ImUserService;
import com.nomito.minimito.vo.CreateActivityVo;
import com.nomito.minimito.vo.GrouperVo;
import com.nomito.minimito.vo.NoExistGroupMemberVo;
import com.nomito.minimito.vo.RespGroupInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 凌月青缃
 * @date 2021/5/15
 */
@Api(tags = "群聊接口")
@RestController
@CrossOrigin
@RequestMapping("/front/group")
public class FGroupController {
    @Autowired
    ImGroupfriendService groupfriendService;
    @Autowired
    ImGroupService groupService;
    @Autowired
    ImUserService userService;
    /**
     * 创建群聊,活动id即群id
     * 群id设置为活动id
     */
//    @ApiOperation(value = "创建群聊")
//    @PostMapping("/createGroup")
//    public R createGroup(@RequestParam("userId") Long userId ,@RequestParam("activityId")Long activityId){
//        Long accout = groupService.createGroup(userId,activityId);
//        return R.ok().put("groupAccount",accout);
//    }



    /**
     * 群聊成员信息查询
     */
    @ApiOperation(value = "群聊全部成员信息查询")
    @GetMapping("/queryGroupAllHuman")
    public R queryGroupAllHuman(Long groupId){
        List<GrouperVo> voList = groupfriendService.queryGroupAllHuman(groupId);
        return R.ok().setData(voList).put("groupId",groupId);
    }


    /**
     * 群聊列表查询
     */
    @ApiOperation(value = "群聊列表查询")
    @GetMapping("/myGroups")
    public R queryMyGroups(Long userId){
        if (StringUtils.isEmpty(userId)){
            return R.error("用户id为空");
        }
        //数据库查询群聊列表
        List<RespGroupInfoVo> myGroups = groupfriendService.queryMyGroups(userId);
        return R.ok().setData(myGroups);
    }


    /**
     * 不存在的群成员信息
     */
    @ApiOperation(value = "不存在的群成员信息")
    @GetMapping("/noExistGroupMember")
    public R noExistGroupMember(Long userId){
        if (StringUtils.isEmpty(userId)){
            return R.error("用户id为空");
        }
        //数据库查询群聊列表
        NoExistGroupMemberVo noExistGroupMember = userService.noExistGroupMember(userId);
        return R.ok().setData(noExistGroupMember);
    }




}
